package com.sun.web.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by pullFoot_youth on 2017/3/12.
 */
public class CustomExceptionResolver implements HandlerExceptionResolver{



    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {

        CustomException customException = null;

        if(ex instanceof CustomException){

            customException = (CustomException)ex;
        }else{
            customException = new CustomException("未知异常，非自定义异常");
        }

        String message = customException.getMessage();

        ModelAndView mav = new ModelAndView();

        mav.setViewName("/error");
        mav.addObject("message", message);


        return mav;
    }
}
